// page/component/new-pages/user/address/address.js
const db = wx.cloud.database()
const app= getApp()
Page({
  data:{
    address:{
      name:'',
      phone:'',
      detail:''
    }
  },
  onLoad() {
    var that = this
    wx.getStorage({
      key: 'address',
      success: (res) => {
        that.setData({
          address: res.data
        })
      },
    })
  },
  
  formSubmit(e){
    const value = e.detail.value;
    if (value.name && value.phone && value.detail){
      //将用户地址更新的云数据库
      db.collection("sg_address").doc(app.globalData.openid).set({
            data:value
      })
      wx.setStorage({
        key: 'address',
        data: value,
        success(){
          wx.navigateBack();
        }
      })
    }else{
      wx.showModal({
        title:'提示',
        content:'请填写完整资料',
        showCancel:false
      })
    }
  },
  
})